package one;

import java.util.*;

public class test17086 {
    public static void main(String[] args) {
        ArrayList<String> arrayList = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String s = scanner.next();
        char[] array = new char[n];
        for (int i = 0; i < n; i++) {
            array[i]=s.charAt(i);
        }
        Perm(array,0,n-1,arrayList);
        Collections.sort(arrayList, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.println(i+1+" "+arrayList.get(i));
        }
    }

    private static void Perm(char[] array, int k, int m,ArrayList<String> arrayList) {
        if(k==m){
            arrayList.add(String.valueOf(array));
        }else {
            for(int i=k;i<=m;i++){
                Swap(i,k,array);
                Perm(array,k+1,m,arrayList);
                Swap(i,k,array);
            }
        }
    }

    private static void Swap(int a, int b,char[] array) {
        char temp = array[a];
        array[a]=array[b];
        array[b]=temp;
    }
}
